package org.seckill.logic;

import org.seckill.model.Seckill;
import org.seckill.utils.RedisClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Wrb
 * @date 2019/7/5 15:17
 */
@Component
public class RedisLogic {

	@Autowired
	private RedisClient redisClient;

	public Seckill getSeckill(Long seckillId) {
		String key = "seckill:" + seckillId;
		// 采用自定义序列化
		return redisClient.get(key, Seckill.class);
	}

	public void putSeckill(Seckill seckill) {
		String key = "seckill:" + seckill.getSeckillId();
		long timeout = 60 * 60;
		redisClient.setWithExpire(key, seckill, timeout);
	}

}
